package org.hylexus.hadoop.hadoop_2_test.rpc;

import java.io.File;
import java.io.IOException;

import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.ipc.RPC.Server;

public class RPCServer implements RPCInterface {

	@Override
	public String hello(String name) {
		return "hello " + name;
	}

	public static void main(String[] args) {

		try {
			File workaround = new File(".");
			System.getProperties().put("hadoop.home.dir", workaround.getAbsolutePath());
			new File("./bin").mkdirs();
			new File("./bin/winutils.exe").createNewFile();
			Server server = new RPC.Builder(new Configuration()).setProtocol(RPCInterface.class)
					.setBindAddress("192.168.0.109").setInstance(new RPCServer()).setPort(8888).build();
			server.start();
		} catch (HadoopIllegalArgumentException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
